{% extends "base.html" %}

{% block content %}
<div class="container mt-3">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('index') }}">首页</a></li>
            <li class="breadcrumb-item"><a href="#">{{ owner.username }}</a></li>
            <li class="breadcrumb-item"><a href="{{ url_for('repo_detail', username=owner.username, repo_name=repo.name) }}">{{ repo.name }}</a></li>
            <li class="breadcrumb-item active">{{ directory.name }}</li>
        </ol>
    </nav>

    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2>
            <span>{{ directory.name }}</span>
        </h2>
        {% if current_user.id == repo.owner_id or Collaborator.query.filter_by(repository_id=repo.id, user_id=current_user.id, permission='write').first() %}
        <div>
            <button class="btn btn-sm btn-outline-secondary">新建文件</button>
            <button class="btn btn-sm btn-outline-secondary ms-2">上传文件</button>
        </div>
        {% endif %}
    </div>

    <div class="list-group">
        {% for file in files %}
        <a href="{{ url_for('view_file', username=owner.username, repo_name=repo.name, file_path=file.path) }}" class="list-group-item list-group-item-action">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    {% if file.is_directory %}
                    <i class="bi bi-folder-fill text-warning me-2"></i>
                    {% else %}
                    <i class="bi bi-file-earmark-text me-2"></i>
                    {% endif %}
                    <span>{{ file.name }}</span>
                </div>
                <span class="text-muted">
                    {% if file.is_directory %}目录{% else %}文件{% endif %}
                </span>
            </div>
        </a>
        {% endfor %}
    </div>
</div>
{% endblock %}
